package com.zhiyou100.review.day021.homework.homework4;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @packageName: UploadFile
 * @className: com.zhiyou100.review.day021.homework.homework4
 * @Description: TODO 客户端，上传文件
 * @author: yang
 * @date: 7/2/20
 */
public class UploadFile {
    private static final String FILE_NAME = "/Users/yang/Downloads/test/send/a.txt";
    private static final int PORT = 10010;
    private static final String IP = "127.0.0.1";
    private static final int SERVER_PORT = 10086;

    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket(PORT);
        String fileContent = com.zhiyou100.review.day021.homework.homework3.UploadFile.getFileContent(FILE_NAME);
        // 获取文件的内容

        DatagramPacket localhost =
                new DatagramPacket(fileContent.getBytes(),
                        0, fileContent.length(),
                        InetAddress.getByName(IP), SERVER_PORT);
        //  把数据封装成 datagramPacket
        socket.send(localhost);
        // 发送 包

        socket.close();
        // 关闭


    }
}
